Page({

  /**
   * 页面的初始数据
   */
  data: {
    result: [],
    noeVal:false,
    listData: [{
        id: 12,
        goodsName: "GF01",
        goodsNo: "70",
        goodsCount: "1",
        goodsUpper:'2000',
        ischecked:false
      },{
        id: 13,
        goodsName: "GF02",
        goodsNo: "70",
        goodsCount: "1",
        goodsUpper:'2000',
        ischecked:false
      },{
        id: 14,
        goodsName: "GF03",
        goodsNo: "70",
        goodsCount: "1",
        goodsUpper:'2000',
        ischecked:false
      },
    ]
  },
  onChangeAll(event){
    console.log(event);
    let that = this
    that.setData({
      noeVal:!that.data.noeVal
    })
    let arr = that.data.listData
    if(event.detail){
      let arrayAll = []
      arr.map(item=>{
        arrayAll.push(item.id)
        item.ischecked = true
      })
      that.setData({
        result:arrayAll,
        listData:arr
      })
      console.log(arrayAll);
    }else{
      arr.map(item=>{
        item.ischecked = false
      })
      that.setData({
        result:[],
        listData:arr
      })
    }
  },
  onChange(event) {
    let that = this
    console.log(event)
    console.log(event.detail)
    const {
      key
    } = event.currentTarget.dataset;
    let arr = that.data.listData
    arr.map(item=>{
      if(item.id==event.currentTarget.dataset.name){
        item.ischecked = !item.ischecked
      }
    })
    console.log(that.pitchon(arr),'选中数据');
    that.setData({
      listData:arr
    })
    console.log(this.data.listData)
    this.setData({
      result: that.pitchon(arr)
    });
    // console.log(this.data.result);
    if(this.data.result.length==this.data.listData.length){
      this.setData({
        noeVal:true
      })
    }else{
      this.setData({
        noeVal:false
      })
    }
  },
  pitchon(data){
    let arr = []
    data.map(item=>{
      if(item.ischecked){
        arr.push(item.id)
      }
    })
    return arr
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})